package com.example.myapplication.part15;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.R;

import java.io.File;
import java.util.ArrayList;

public class Part15Activity extends AppCompatActivity {

    // 声明 views 和 files 变量
    private ArrayList<View> views;
    private ArrayList<File> files;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_part15); // 确保设置了布局文件

        // 初始化 views 和 files
        views = new ArrayList<>();
        files = new ArrayList<>();

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);

        // 添加视图到 views 列表
        View view0 = getLayoutInflater().inflate(R.layout.listview, null);
        View view1 = getLayoutInflater().inflate(R.layout.listview, null);
        View view2 = getLayoutInflater().inflate(R.layout.listview, null);

        views.add(view0);
        views.add(view1);
        views.add(view2);

        // 设置 ViewPager 的适配器
        viewPager.setAdapter(new PageViewAdapter(views));

        // 添加文件到 files 列表
        files.add(new File("项目一"));
        files.add(new File("项目二"));
        files.add(new File("项目三"));
        files.add(new File("项目四"));

        // 获取 ListView 并设置适配器
        ListView listView = (ListView) view0.findViewById(R.id.listview_phone);
        listView.setVisibility(ListView.VISIBLE);
        listView.setAdapter(new ListViewAdapter(files, getLayoutInflater()));
    }
}